package ca.swank.hq.ai;

import ca.swank.hardquor.*;

/**
* @author Jesse Wilson
* @version 1.0 4/1/2002
*/
public class AIUser implements hardquorUser
{
  public static final int AI_TYPE_LOOKAHEAD = 4;
  public static final int AI_TYPE_TREE = 5;

  private String serverIp;
  private String userName;
  public String getUserName() {
	return userName;
}

public void setUserName(String userName) {
	this.userName = userName;
}

public hardquorClient getClient() {
	return client;
}

public void setClient(hardquorClient client) {
	this.client = client;
}

private hardquorClient client;

  /**
   * constructs a new aiUser which attempts to connect to the server as username
   */
  public AIUser(String serverIp, String userName)
  { this.serverIp = serverIp;
    this.userName = userName;
    
    client = new hardquorClient(this);
    client.connect(serverIp);
  }
  
  /**
   * called upon connection to a hardquor game server. Upon having this method
   */
  public void notifyRequestUserName(String reason)
  { System.out.println("username requested for reason: " + reason);
    client.tryUsername(userName);
  }

  /**
   * provides a list of online users upon connection to a hardquor game.
   */
  public void notifyUserList(String[] users)
  { System.out.println("received userlist: " + users);
  }

  /**
   * notification that another user has disconnected from the hardquor game
   */
  public void notifyUserGone(String username)
  { System.out.println("user gone: " + username);
  }

  /**
   * notification that another user has connected to the current hardquor game
   */
  public void notifyUserNew(String username)
  { System.out.println("user new: " + username);
  }

  /**
   * a chat message received from the specified user. Chat messages should
   */
  public void notifySpeak(String user, String message)
  { System.out.println(user + ": " + message);
  }

  /**
   * an incoming game request from another user on the current hardquor server.
   */
  public void notifyGameRequest(hardquorGameRequest request)
  { System.out.println("game requested");
    client.acceptGameRequest(request);
  }

  /**
   * requests the user create an instance of an implementation of the
   */
  public hardquorUserGame startGame(hardquorGameClient gameClient, int playerNumber)
  { System.out.println("game start");
    hardquorUserGame userGame = null;
    userGame = new TreeAIGame(gameClient, playerNumber, userName);

    return userGame;
  }
  
  /**
   * starts a new WalkerUser which accepts all requests on specified server and name
   */
  public static void main(String[] args)
  { if(args.length != 2)
    { System.out.println("usage: aiUser [server_ip] [aiName]");
    } else
    { AIUser user = new AIUser(args[0], args[1]);
    }
  }

}